package com.sunspring.zdcall.entity;

import com.sunspring.zdcall.common.constant.enums.ClientEnum;
import com.sunspring.zdcall.param.ClientParam;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 客户端信息
 * @author wulei
 * @date 2019-01-03
 **/
@Data
public class ZdBaseClient {

    /**
     * 客户端id 对应机器MAC号
     */
    private String clientId;

    /**
     * 客户端注册名称
     */
    private String clientName;

    /**
     * 客户端类型
     *  1:呼号客户端
        2:显示客户端
        3:打印客户端
         4:呼号+小屏显示
     */
    private Integer clientType;

    /**
     * 模板id
     */
    private Integer templateId;

    /**
     * 分屏编号
     */
    private String screenId;

    /**
     * 是否启用语音 1-启用 2-关闭
     */
    private Integer voiceState;

    /**
     * 语速 -10-10
     */
    private Integer voiceSpeed;

    /**
     * 音量 0-100
     */
    private Integer volume;

    /**
     * 播报规则
     默认：请|$queueId|号|$name|到|$checkRoomName|就诊（参数前后有分隔符）
     */
    private String callRule;

    /**
     * 屏显提示语
     */
    private String markedWords;

    /**
     * 1-自动打印
     * 2-手动打印
     */
    private Integer autoType;

    /**
     * 客户端状态
     * 1-已激活
     2-未激活
     3-新注册
     */
    private Integer clientState;

    /**
     * 打印机
     */
    private String printer;

    /**
     * 服务端主页地址
     */
    private String serverUrl;


    public static ZdBaseClient clientFactory(String mac, Integer clientType) {
        ZdBaseClient client;
        if (clientType == ClientEnum.call.getCode()) {
            client  = defaultPrinterClient();
        }else {
            client = defaultShowClient();
        }
        client.setClientId(mac);
        return client;
    }

    /**
     * 默认的打印端参数
     * @return ClientParam
     */
    private static ZdBaseClient defaultPrinterClient() {
        ZdBaseClient client = new ZdBaseClient();
        client.setClientType(ClientEnum.call.getCode());
        client.setTemplateId(1);
        client.setAutoType(1);
        return client;
    }

    /**
     * 默认的屏显端参数
     * @return ClientParam
     */
    private static ZdBaseClient defaultShowClient() {
        ZdBaseClient client = new ZdBaseClient();
        client.setClientType(ClientEnum.show.getCode());
        client.setVoiceState(1);
        client.setVoiceSpeed(-3);
        client.setVolume(50);
        client.setCallRule("请|$queueId|号|$name|到|$checkRoomName|就诊");
        client.setMarkedWords("请患者到候诊大厅等待");
        return client;
    }
}
